package com.aitest.wyjai.autoconfig;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.ollama.api.OllamaModel;
import org.springframework.aop.Advisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class AIConfig {

    @Bean
    public  ChatMemory buildChatMemory() {
        return new InMemoryChatMemory();
    }

    @Bean
    public ChatClient buildClient(OllamaChatModel model) {
        List<Advisor> advisorList=new ArrayList<>();
        return ChatClient.builder(model)
                .defaultSystem("你的身份是一名中学语文老师，你的名字叫娄丹丹，请你以娄丹丹老师的身份回答问题")
                .defaultAdvisors(new SimpleLoggerAdvisor()
                                ,new MessageChatMemoryAdvisor(buildChatMemory()))//MessageChatMemoryAdvisor
                .build();
    }


}
